package day32.stream;

import java.util.Arrays;
import java.util.List;
import java.util.function.UnaryOperator;
import java.util.stream.Stream;

public class Demo01 {
	public static void main(String[] args) {
		test01();
	}

	// 获取Stream
	private static void test01() {

		List<String> list = Arrays.asList("aaa", "bbb", "ccc", "ddd", "eee", "fff");

		// 1. 通过Collectio接口中的stream()方法, 获取串行流
		Stream<String> stream = list.stream();
		// stream.forEach(e -> System.out.println(e));
		//		list.stream().forEach(System.out::println);
		//		list.forEach(System.out::println);

		// 2. 通过Collection接口的parallelStream()方法, 获取并行流
		Stream<String> stream2 = list.parallelStream();

		// 3. 通过Arrays类中的stream()方法, 获取数组的流
		String[] arr = { "aaa", "bbb", "ccc", "ddd", "eee", "fff" };
		Stream<String> stream3 = Arrays.stream(arr);

		// 4. 通过Stream接口中静态方法
		Stream<String> stream4 = Stream.of("aaa", "bbb", "ccc", "ddd", "eee", "fff");

		// 5. 
		// 第1个参数: 种子
		// 第2个参数: 一元运算lambda表达式, UnaryOperator<T>
		// 从种子开始, 根据一元运算lambda表达式的操作, 产生一个无限流
		UnaryOperator<Integer> uo = n -> n + 1;
		Stream<Integer> stream5 = Stream.iterate(0, uo);
		stream5.forEach(System.out::println);
	}
}
